package za.org.jcicada.katcp;

/**
 * StrategyBase.java
 *
 * @author Simon Cross
 * @author Adrianna Pinska
 *
 * Created on October 30, 2008, 16:08
 */

import za.org.jcicada.katcp.ISamplingStrategy;
import za.org.jcicada.katcp.ISensor;
import za.org.jcicada.katcp.StrategyDiff;
import za.org.jcicada.katcp.StrategyEvent;
import za.org.jcicada.katcp.StrategyNone;
import za.org.jcicada.katcp.StrategyPeriod;

/**
 * An abstract base class for KAT sensors strategy.
 */
public abstract class StrategyBase
implements ISamplingStrategy {

    /**
     * Factory method for constructing ISamplingStrategy instances.
     *
     * @param sensor  The sensor to sample on.
     * @param type    The sampling strategy type.
     * @param params  The sampling strategy parameters.
     * @return  The sampling strategy instance.
     */
    public static ISamplingStrategy strategyFactory(ISensor sensor, ISamplingStrategy.Strategy type, String[] params) {
        switch (type) {
            case NONE:
                return new StrategyNone(params);
            case DIFF:
                return new StrategyDiff(sensor, params);
            case PERIOD:
                return new StrategyPeriod(params);
            case EVENT:
                return new StrategyEvent(params);
            case AUTO:
                return new StrategyAuto(params);
            default:
                throw new IllegalArgumentException("strategyFactory expects a known strategy type.");
        }
    }

    /**
     * The type for this strategy.
     */
    protected ISamplingStrategy.Strategy type;

    /**
     * The strategy parameters for this strategy.
     */
    protected String[] params;

    /**
     * Constructs a StrategyBase object.
     *
     * @param type    The type for this strategy.
     * @param params  The strategy parameters for this strategy.
     */
    public StrategyBase(ISamplingStrategy.Strategy type, String[] params) {
        this.type = type;
        this.params = params;
    }

    /**
     * Return the strategy type.
     *
     * @return  The type of this strategy.
     */
    public ISamplingStrategy.Strategy getType() {
        return type;
    }

    /**
     * Return the formatted strategy parameters.
     *
     * @return  The strategy parameters for this strategy.
     */
    public String[] getStrategyParameters() {
        return params;
    }

}
